#ifndef MJPEG_SERVER_H
#define MJPEG_SERVER_H

#include "../../BaseEncoder.hpp"
#include <crow.h>
#include <crow/app.h>
#include <crow/routing.h>
#include <crow/websocket.h>
#include <list>
#include <opencv2/opencv.hpp>
#include <thread>

class Encoder : public BaseEncoder {
private:
  int imgWidth, imgHeight;
  ImageType imgType;
  int ServerPort;

  cv::Mat image;
  long imageSize;

  crow::SimpleApp app;
  std::list<crow::websocket::connection *> connList;
  std::thread workThread;

  bool RunStatus;

public:
  Encoder(const std::string &port);
  virtual ~Encoder();
  virtual void StartStream(int width, int height,
                           const ImageType &type) override final;
  virtual void InputImage(const unsigned char *img) override final;
  virtual void EndStream() override final;
  virtual bool GetStatus() override final;
};

#endif
